import { _decorator, Component, Node, instantiate, Label, game, AudioSource, Prefab, assetManager, AudioClip } from 'cc';
import { mb, mb_base_cp,mb_audio } from 'db://magic-book/src';
const { ccclass, property } = _decorator;

@ccclass('audio_layout_play_music')
export class audio_layout_play_music extends mb_base_cp {

    @property(Prefab)
    btn_template: Prefab = null;

    onLoad() {
        assetManager.resources.loadDir("audio/music", AudioClip, (err, data: AudioClip[]) => {
            mb_audio.load_res(data);
            for (let i = 0; i < data.length; i++) {
                const node = instantiate(this.btn_template);
                node.on("click", () => {
                    mb_audio.play_music(node.name, true);
                });
                node.name = data[i].name;
                node.getComponentInChildren(Label).string = node.name;
                this.node.addChild(node);
            }
        });
    }

}

